package com.xyzq.reks.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;

@Entity
@Table(name = "account_money")
public class AccountMoney extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8941045220526651910L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "FK_ACCOUNT_ACCOUNT", nullable = false)
	private Account account;
	@Column(scale = 2)
	private Double money;
	@Temporal(TemporalType.DATE)
	@Column(name = "day")
	private Date day;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "sub_time")
	private Date subTime;

	public Long getId() {
		return id;
	}

	public Account getAccount() {
		return account;
	}

	public Double getMoney() {
		return money;
	}

	public Date getDay() {
		return day;
	}

	public Date getSubTime() {
		return subTime;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public void setMoney(Double money) {
		this.money = money;
	}

	public void setDay(Date day) {
		this.day = day;
	}

	public void setSubTime(Date subTime) {
		this.subTime = subTime;
	}

	@Override
	public String toString() {
		ToStringBuilder builder = new ToStringBuilder(this,
				ToStringStyle.DEFAULT_STYLE);
		builder.append("id", id);
		builder.append("account", account);
		builder.append("money", money);
		builder.append("day", day);
		builder.append("subTime", subTime);
		return builder.toString();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AccountMoney other = (AccountMoney) obj;
		if (account == null) {
			if (other.account != null)
				return false;
		} else if (!account.equals(other.account))
			return false;
		if (day == null) {
			if (other.day != null)
				return false;
		} else if (!day.equals(other.day))
			return false;
		if (money == null) {
			if (other.money != null)
				return false;
		} else if (!money.equals(other.money))
			return false;
		if (subTime == null) {
			if (other.subTime != null)
				return false;
		} else if (!subTime.equals(other.subTime))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((account == null) ? 0 : account.hashCode());
		result = prime * result + ((day == null) ? 0 : day.hashCode());
		result = prime * result + ((money == null) ? 0 : money.hashCode());
		result = prime * result + ((subTime == null) ? 0 : subTime.hashCode());
		return result;
	}

}
